//如何右键能够直接创建？？扩展编辑器功能
Shader "toon/Template"
{
    Properties
    {
        _MainTex ("Texture", 2D) = "white" {}
        _OutlineWidth ("Outline Width", float) = 1
    }
    SubShader
    {
        Tags 
        { 
            "Queue"="Geometry"
            "RenderPipeline" = "UniversalRenderPipeline"//改造1
        }
        // LOD 100
        Pass
        {
            Name "Unlit"
            Tags
            {
                "LightMode"="ForwardBase"//改造6
            }
            HLSLPROGRAM//改造2
            #pragma vertex vert
            #pragma fragment frag
            // #include "UnityCG.cginc"
            // #include "Lighting.cginc"
            #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"//改造3
            #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"//改造3

            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
                float3 normal : NORMAL;
            }

            struct v2f
            {
                float2 uv : TEXCOORD0;
                float4 pos : SV_POSITION;
                float3 worldNormal : TEXCOORD1;
                float3 worldPos : TEXCOORD2;
            }
            sampler2D _MainTex;
            float4 _MainTex_ST;
            v2f vert (appdata v)
            {
                v2f o;
                // o.vertex = UnityObjectToClipPos(v.vertex);
                o.pos = TransformObjectToHClip(v.vertex);//改造4
                // o.uv = TRANSFORM_TEX(v.uv, _MainTex);
                // o.worldNormal = UnityObjectToWorldNormal(v.normal);
                // o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
                return o;   
            }

            // fixed4 frag (v2f i) : SV_Target
            half4 frag (v2f i) : SV_Target //改造5
            {
                // fixed3 worldNormal = normalize(i.worldNormal);
                // fixed3 worldLightDir = normalize(UnityWorldSpaceLightDir(i.worldPos));
                fixed4 col = tex2D(_MainTex, i.uv);//改造5
                // fixed3 ambient = UNITY_LIGHTMODEL_AMBIENT.rgb * albedo;
                // fixed3 diffuse = _LightColor0.rgb * albedo * max(0, dot(worldNormal, worldLightDir));
                // fixed3 color = ambient + diffuse;
                return col;
            }
            ENDHLSL //改造2
        }

//法线外扩，只渲染背面，剔出正面
        Pass
        {
            Name "Outline"
            Tags
            {
                //要特定的LightMode名字才能添加pass
                "LightMode"="SRPDefaultUnlit"
            }
            Cull Front //正面剔除


            HLSLPROGRAM//改造2
            #pragma vertex vert
            #pragma fragment frag
            // #include "UnityCG.cginc"
            // #include "Lighting.cginc"
            #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"//改造3
            #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"//改造3

            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
                float3 normal : NORMAL;
            }

            struct v2f
            {
                float2 uv : TEXCOORD0;
                float4 pos : SV_POSITION;
                float3 worldNormal : TEXCOORD1;
                float3 worldPos : TEXCOORD2;
            }
            sampler2D _MainTex;
            float4 _MainTex_ST;
            float _OutlineWidth;

            v2f vert (appdata v)
            {
                v2f o;
                float3 pos = v.vertex + v.normal * _OutlineWidth;
                o.pos = TransformObjectToHClip(pos);//改造4
                o.uv = TRANSFORM_TEX(v.uv, _MainTex);
                return o;   
            }

            // fixed4 frag (v2f i) : SV_Target
            half4 frag (v2f i) : SV_Target //改造5
            {
                return 1;
            }
            ENDHLSL //改造2
        }
    }
}